home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr13 / veced100.zip / CONVMAIN.CPP < prev    next >
C/C++ Source or Header  |  1995-01-19  |  8KB  |  229 lines

  1. //*************************************************************************
  2. //*************************************************************************
  3. /*
  4.  
  5. Information for the potential creator of a vector conversion utility for
  6. Vecedit objects!!!!  This file is the main module of the program.  It is
  7. recommended that you do not modify any of the original variables of the
  8. program.  I myself don't even remember what everything does (I have long
  9. since switched from C++/ASM to pure ASM for my demo coding, so I've
  10. forgotten some stuff about the original engine).
  11.  
  12. The code included will load objects into my original C++ object storage
  13. format and then convert them into a simpler format (see convdefs.h).  The
  14. following variables are important:
  15.  
  16. long         *rawpt        // array of raw vertices of object
  17. long         *grppt        // group points of object
  18. long         *norms         // normal vectors for polygons
  19. long         *vertnorms        // vertex normals (used for gourad shading)
  20. face         *thefaces        // faces/ polygons of object
  21. outgou         *thegous        // gourad vertex information
  22. outtex         *thetexs        // texture vertex information
  23.  
  24.  
  25. NOTE:  The unsigned array below do not really need to be accessed
  26.        directly--their information is pointed to by "thefaces"
  27.  
  28. unsigned     *faceverts        // a list which contains the ordered sets of
  29.                 // vertex offsets used by the polygons, i.e.
  30.                 //  {0, 2, 4, 6} stored in the array would
  31.                 // represent a poly consisting of vertex 0,
  32.                 // 2, 4, and 6 in that order.
  33.  
  34. unsigned     abc[0].vs        // number of vertices in object
  35. unsigned     abc[0].ps        // number of polygons/ faces in object
  36. unsigned     numnorm        // number of polygon normals
  37. unsigned     numgrp        // number of group points
  38. unsigned     xyz[0].vn        // number of vertex normals/ gourad vertices
  39.  
  40.  
  41. I recommend looking at the text output in the conversion routine to get an
  42. idea of how to extract important information from the data structures above.
  43. The above format really is very simple.  See additional information in the
  44. other two files.
  45.  
  46. //*************************************************************************
  47. //*************************************************************************/
  48.  
  49.  
  50.  
  51. #include <dos.h>
  52. #include <conio.h>
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <malloc.h>
  56. #include <dir.h>
  57. #include "convdefs.h"
  58.  
  59. extern unsigned _stklen = 35000;
  60. void load3D(numstuff *abc, unsigned *numgrps, unsigned *numnorms, unsigned nullpoly, long *rawpt, long *grppt, unsigned *grplist, polystruc *locpoly, long *rawnorms, rawedgeverts *edgees, texedge *texed, texstats *texts, texpoly *goutexpolys, unsigned char *bitmaparr[], unsigned *bitmapsizearray, gouvert *somegous, long *vertnorm, unsigned *numbmap, numgoustuff *xyz, unsigned *texpolused, unsigned *texpoltotal, texpoly *texpoarr[]);
  61. void conv3D(numstuff *abc, long *rawpt, unsigned *grplist, polystruc *locpoly, long *rawnorms, rawedgeverts *edgees, texedge *texed, texstats *texts, gouvert *somegous, numgoustuff *xyz, face *thefaces, outgou *thegous, outtex *thetexs, unsigned *faceverts);
  62. void dumpved04(numstuff abc, long *rawpt, face *thefaces);
  63.  
  64.  
  65. void allocerr(unsigned parm)
  66. {
  67.    cprintf("Not enough memory to allocate buffer %d/10\n\r",parm);
  68.    getch();
  69.    exit(1);  /* terminate program if out of memory */
  70. }
  71.  
  72.  
  73. // here are some main object holding arrays
  74.  
  75. unsigned char  *bitmaparrays[200];    // groups of bitmaps
  76. texpoly *texpolyarrays[200];    // groups of texture polys
  77. unsigned bitmapsizes[400];    // sizes of bitmaps
  78. unsigned texgroupsizes[200];    // number of texture polys per group
  79. unsigned texgroupused[200];    // number of texture polys used per group
  80. unsigned grplist[800];        // group list (800 total polys)
  81.  
  82. gouvert somegous[800];
  83.  
  84. char         mainpal[768];    // main object palette
  85.  
  86. void main()
  87. {
  88. unsigned count;
  89.  
  90. //Following are the variables with the numbers of each type of object data
  91.  
  92. numstuff     abc[1]={0,0,0};    // number of polys, edges, vertices
  93. numgoustuff  xyz[1]={0,0,0};    // num of texpolys, texedges, gouverts
  94. unsigned     numgrp=0;        // number of group points
  95. unsigned     numnorm=0;        // number of polygon normals
  96. unsigned     numbitmap=0;    // number of bitmaps
  97.  
  98. //Following are the main object holding arrays used in the program
  99.  
  100. rawedgeverts edgees[1600];    // edge array
  101.  
  102. long         *rawpt;        // raw points (2400 total longs)
  103. long         *grppt;        // group points (1200 total longs)
  104.  
  105. texedge         *texed;        // texture edges (200 total in editor)
  106. texstats     *texts;        // texture stats (200 total in editor)
  107. texpoly         *texpos;        // gourad texture polys (50 total in editor)
  108. long         *vertnorms;    // vertex normals (50 total in editor)
  109. polystruc    *polys;        // polygons (800 total allocated)
  110.  
  111. face         *thefaces;        // faces/ polygons of object
  112. outgou         *thegous;        // gourad vertex information
  113. outtex         *thetexs;        // texture vertex information
  114.  
  115. unsigned     *faceverts;    // vertices belonging to a face
  116.  
  117. unsigned     nullpolyval;    // location (offset) of null polygon
  118.  
  119. long         norms[2400];    // raw normal array (800 polygons)
  120.  
  121.  
  122.  
  123. FILE *output;
  124. unsigned lastloc;
  125.  
  126.  
  127.  
  128. // Memory allocation for large data structures
  129.  
  130. if ((rawpt = (long *) malloc(14400)) == NULL)   allocerr(1);
  131. grppt=&rawpt[2400];
  132. if ((polys = (polystruc *) malloc(800*16)) == NULL)   allocerr(2);
  133. if ((thefaces = (face *) malloc(800*24)) == NULL)   allocerr(3);
  134. if ((thegous = (outgou *) malloc(2000*4)) == NULL)   allocerr(4);
  135. if ((thetexs = (outtex *) malloc(2000*4)) == NULL)   allocerr(5);
  136.  
  137. if ((faceverts = (unsigned *) malloc(4000*2)) == NULL)   allocerr(6);
  138.  
  139. if ((texed = (texedge *) malloc(2000*32)) == NULL)   allocerr(7);
  140. if ((texts = (texstats *) malloc(2000*16)) == NULL)   allocerr(8);
  141. if ((texpos = (texpoly *) malloc(500*16)) == NULL)   allocerr(9);
  142. if ((vertnorms = (long *) malloc(800*12)) == NULL)   allocerr(10);
  143.  
  144.  
  145. // Following are the variables used in the main menu of the program
  146.  
  147. char maincomm;
  148. unsigned char *tempcharptr;
  149.  
  150. // Miscellaneous initializations
  151.  
  152. for(count=0;count<=99;count++)
  153.    {
  154.    texgroupused[count]=0;
  155.    }
  156.  
  157.  
  158. // set up miscellaneous stuff
  159.  
  160. nullpolyval=FP_OFF(polys) + 16*799;
  161. polys[799].backfill=-1;
  162.  
  163.  
  164. while(1)
  165.    {
  166. updatethispuppy:
  167.  
  168.    clrscr();
  169.    cprintf("\n\r");
  170.    cprintf(" CONV v1.00-   Vector object conversion utility\n\r");
  171.    cprintf("                by Jason Hoerner\n\n\r");
  172.    cprintf("             1.  Read in 3D object from file\n\r");
  173.    cprintf("             2.  Write 3D object to file\n\r");
  174.  
  175.  
  176. justgetakey:
  177.    maincomm=getch();
  178.  
  179.    switch(maincomm)
  180.       {
  181.       case '1':{
  182.            load3D(abc, &numgrp, &numnorm, nullpolyval, rawpt, grppt, grplist, polys, norms, edgees, texed, texts, texpos, bitmaparrays, bitmapsizes, somegous, vertnorms, &numbitmap, xyz, texgroupused, texgroupsizes, texpolyarrays);
  183.            conv3D(abc, rawpt, grplist, polys, norms, edgees, texed, texts, somegous, xyz, thefaces, thegous, thetexs, faceverts);
  184.            asm jmp updatethispuppy;
  185.            }
  186.  
  187.       case '2':{
  188.                  dumpved04(abc[0], rawpt, thefaces);
  189.            asm jmp updatethispuppy;
  190.            }
  191.  
  192.       case  27:
  193.       case 'q':
  194.       case 'Q':
  195.       case 'x':
  196.       case 'X':{
  197.            cprintf("\n\n\rAre you sure you want to quit?  (Y/N)");
  198.            maincomm=getch();
  199.            if((maincomm>='a')&&(maincomm<='z')) maincomm=maincomm-'a'+'A';
  200.            if(maincomm=='Y') asm jmp weouttahere;
  201.            if(maincomm==0) getch();
  202.            asm jmp updatethispuppy;
  203.            }
  204.       default :asm jmp justgetakey;
  205.       }
  206.  
  207.    }
  208.  
  209. weouttahere:
  210.  
  211.    for(count=0;count<numbitmap;count++)
  212.       {
  213.       tempcharptr=bitmaparrays[count];
  214.       free(tempcharptr);
  215.       }
  216.  
  217.    free(vertnorms);
  218.    free(texpos);
  219.    free(texts);
  220.    free(texed);
  221.    free(rawpt);
  222.    free(polys);
  223.    free(thefaces);
  224.    free(thegous);
  225.    free(thetexs);
  226.    exit(0);
  227.  
  228. }
  229.